package ch.uzh.ifi.sonar.importers;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import net.sourceforge.clearcase.commandline.CommandLauncher;
import net.sourceforge.clearcase.commandline.CommandLine;
import net.sourceforge.clearcase.commandline.Response;
import net.sourceforge.clearcase.events.OperationListener;
import net.sourceforge.clearcase.console.OperationListenerImpl;

public class ClearCaseCommand {
	/*
	 * The commandline that should be executed.
	 */
	private CommandLine cline;
	
	public final static String SUCCEED = "succeed";
	public final static String FAIL = "fail";
	// the drive in the machine has to be mapped to the clearcase context view
	public final static String DRIVE = "N:/"; 
	/*
	 * to execute a commandline we need an 
	 */
	private CommandLauncher launcher;
	
	public ClearCaseCommand(CommandLine cmd){
		this.cline = cmd;
		this.launcher = new CommandLauncher();
	}
	

	public Map<String,String[]> execute(){
		Map<String,String[]> result = new HashMap<String,String[]>();
		//FIXME: UI Thread controlling to prevent freezing screen
		Response r = launcher.execute(cline.create(), new File(DRIVE),null,new OperationListenerImpl());
		result.put(ClearCaseCommand.SUCCEED, r.getStdOutMsg());
		result.put(ClearCaseCommand.FAIL, r.getStdErrMsg());
		return result;
	}

}
